CXX = g++
CFLAGS = -std=c++14 -O2 -Wall -g -pthread -I.

# 列出所有需要编译的源文件
SRCS = \
    Buffer/buffer.cpp \
    HTTP/httpconn.cpp \
    HTTP/httprequest.cpp \
    HTTP/httpresponse.cpp \
    Log/log.cpp \
    MultiReactor/Acceptor.cpp \
    MultiReactor/Channel.cpp \
    MultiReactor/DefaultPoller.cpp \
    MultiReactor/Epoller.cpp \
    MultiReactor/EventLoop.cpp \
    MultiReactor/EventLoopThread.cpp \
    MultiReactor/EventLoopThreadPool.cpp \
    MultiReactor/InetAddress.cpp \
    MultiReactor/CurrentThread.cpp \
    MultiReactor/Poller.cpp \
    MultiReactor/Socket.cpp \
    MultiReactor/Thread.cpp \
    MultiReactor/Timer.cpp \
    MultiReactor/TimerQueue.cpp \
    MultiReactor/Timestamp.cpp \
    POOL/sqlconnpool.cpp \
    Server/webserver.cpp \
    main.cpp

# 生成对应的目标文件列表
OBJS = $(SRCS:.cpp=.o)

# 链接选项
LDFLAGS = -pthread -lmysqlclient

# 最终目标
TARGET = webserver

# 默认目标
all: $(TARGET)

# 链接生成可执行文件
$(TARGET): $(OBJS)
	$(CXX) $(CFLAGS) $(OBJS) -o $(TARGET) $(LDFLAGS)

# 编译每个源文件
%.o: %.cpp
	$(CXX) $(CFLAGS) -c $< -o $@

# 清理规则
clean:
	rm -f $(OBJS) $(TARGET)

# 安装规则（可选）
install: $(TARGET)
	cp $(TARGET) /usr/local/bin/

# 声明伪目标
.PHONY: all clean install